package com.aranandroid.customview.ui

import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.aranandroid.customview.R
import com.aranandroid.customview.dialog.CustomDialog
import com.aranandroid.customview.dialog.DialogTipsUtils
import com.aranandroid.customview.dialog.DialogUtils
import kotlinx.android.synthetic.main.activity_dialog.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

class DialogActivity : AppCompatActivity() {

    @SuppressLint("ResourceAsColor")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_dialog)

        /////////////////////////////////自定义dialog/////////////////////////////////////////////////

        getWindowManager()

        //双按钮
        custom_dialog_double.setOnClickListener { v ->
            val builder: CustomDialog.Builder = CustomDialog.Builder(this)
            val customDialog: CustomDialog =
                builder.dialogLayoutId(R.layout.dialog_caseinfo)
                    .title("修改Socket信息")
                    .confirm("保存")
                    .confirmListenter { v,dialog -> Toast.makeText(this, "保存事件", Toast.LENGTH_SHORT).show() }
                    .cancelListenter { v,dialog -> Toast.makeText(this, "取消保存事件", Toast.LENGTH_SHORT).show() }
                    .build()
            customDialog.show()
        }
        //单按钮
        custom_dialog_one.setOnClickListener { v ->
            val builder: CustomDialog.Builder = CustomDialog.Builder(this)
            val customDialog: CustomDialog =
                builder.dialogLayoutId(R.layout.dialog_caseinfo).title("修改Socket信息")
                    .confirm("保存").confirmnoly(true)
                    .confirmListenter { v,dialog -> Toast.makeText(this, "保存事件", Toast.LENGTH_SHORT).show() }
                    .build()
            customDialog.show()
        }

        //无按钮
        custom_dialog.setOnClickListener { v ->
            val builder: CustomDialog.Builder = CustomDialog.Builder(this)
            val customDialog: CustomDialog =
                builder.dialogLayoutId(R.layout.dialog_caseinfo).title("修改Socket信息")
                    .btShow(false)
                    .build()
            customDialog.show()
        }

        //////////////////////////////设置样式//////////////////////////////////////////////////////
        // 设置样式 可以设置在application中； 一次设置全局使用
        CustomDialog.theDefaultStyles = {title, cancel, confirm, config, contentLayout, bottomLayout, middle, lineBottom ->
            title.setBackgroundResource(R.color.colorAccent)
            middle.setBackgroundResource(android.R.color.darker_gray)
            lineBottom.setBackgroundResource(android.R.color.darker_gray)
            cancel.setTextColor(Color.RED)
            confirm.textSize = 16f
            config.radius = 25f
        }
        // 临时设置样式
        custom_dialog_temp_style.setOnClickListener { v ->
            val builder: CustomDialog.Builder = CustomDialog.Builder(this)
            val customDialog: CustomDialog =
                builder.dialogLayoutId(R.layout.dialog_caseinfo)
                    .title("修改Socket信息")
                    .confirm("保存")
                    .confirmListenter { v,dialog -> Toast.makeText(this, "保存事件", Toast.LENGTH_SHORT).show() }
                    .cancelListenter { v,dialog -> Toast.makeText(this, "取消保存事件", Toast.LENGTH_SHORT).show() }
                    .tempStyles{title, cancel, confirm, config, contentLayout, bottomLayout, middle, lineBottom ->
                        title.setBackgroundResource(android.R.color.holo_red_dark)
                        middle.setBackgroundResource(android.R.color.holo_green_light)
                        lineBottom.setBackgroundResource(android.R.color.holo_green_light)
                        cancel.setTextColor(android.R.color.darker_gray)
                        config.radius = 0f
                    }
                    .build()
            customDialog.show()
        }

        /////////////////////////////////DialogUtils///////////////////////////////////////
        //双按钮
        utils_dialog_double.setOnClickListener { v ->
            DialogUtils.instance?.showDialog(this, "确定要删除吗",
                { v,dialog -> Toast.makeText(this, "删除事件", Toast.LENGTH_SHORT).show() },
                { v,dialog -> Toast.makeText(this, "取消删除", Toast.LENGTH_SHORT).show() })
        }


        // 单按钮
        utils_dialog_one.setOnClickListener { v ->
            DialogUtils.instance?.showDialog(this, "程序出现异常bug，请退出程序！",
                { v,dialog -> Toast.makeText(this, "程序退出事件", Toast.LENGTH_SHORT).show() })
        }

        // 提示
        utils_dialog_hint.setOnClickListener { v ->
            DialogUtils.instance?.showDialog(this, "提示内容")
        }




        /////////////////////////////////DialogTipsUtils///////////////////////////////////////
        //双按钮
        utils_tips_dialog_double.setOnClickListener { v ->
            DialogTipsUtils.instance?.showTipsDialog(this, "确定要删除吗",
                { v,dialog -> Toast.makeText(this, "删除事件", Toast.LENGTH_SHORT).show() },
                { v,dialog -> Toast.makeText(this, "取消删除", Toast.LENGTH_SHORT).show() })
        }


        // 单按钮
        utils_tips_dialog_one.setOnClickListener { v ->
            DialogTipsUtils.instance?.showTipsDialog(this, "程序出现异常bug，请退出程序！",
                { v,dialog -> Toast.makeText(this, "程序退出事件", Toast.LENGTH_SHORT).show() })
        }


        GlobalScope.launch {
            repeat(89) {

            }
        }




    }


}